package com.ryskoo.catering.producttemplateattrvalue.repository;

import com.ryskoo.catering.producttemplateattrvalue.domain.ProductTemplateAttrValuePO;
import com.ryskoo.framework.core.repository.BasicJPAImpl;
import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class ProductTemplateAttrValueJPAImpl extends BasicJPAImpl<ProductTemplateAttrValuePO> implements IProductTemplateAttrValueRepository{

    @Override
    public void deleteByAttrId(String attrId) {
        String hql = "delete from ProductTemplateAttrValuePO o where o.attrUuid = :attrId";
        Query query = getH4Session().createQuery(hql);
        query.setString("attrId",attrId);
        query.executeUpdate();
    }

    @Override
    public void deleteByAttrUuids(List<String> idList) {
        String hql = "delete from ProductTemplateAttrValuePO o where o.attrUuid in (:attrId)";
        Query query = getH4Session().createQuery(hql);
        query.setParameterList("attrId",idList);
        query.executeUpdate();
    }

    @Override
    public List<ProductTemplateAttrValuePO> getByAttrUuid(String attrUuid) {
        String hql = "from ProductTemplateAttrValuePO o where o.attrUuid = :attrUuid order by o.position asc ";
        Query query = getH4Session().createQuery(hql);
        query.setString("attrUuid",attrUuid);
        return query.list();
    }
}
